$(document).ready(function() {
	$(".addForm").validate({
		onfocusout: function(element) {
			$(element).valid();
		},
		rules: {
			address: "required",
			fax: "required",
			website: "required",
			link_phone: "required",
			email: {
				required: true,
				email: true
			},
			phone: {
				required: true,
				isPhone: true,
			},
			link_name: "required",
			introduction: "required"
		},
		messages: {
			address: "请输入地址",
			fax:"请输入传真号码",
			website:"请输入网址",
			link_phone: "请输入联系人号码",
			email: {
				required: "请输入Email地址",
				email: "请输入正确的email地址"
			},
			phone: {
				required: "请输入联系号码",
				isPhone: "请正确填写您的联系号码"
			},
			link_name: "请输入联系人名称",
			introduction: "请输入简介"
		}
	});
	$('.addHref').click(function() { //jquery的点击事件 
		$(".croppedfile").empty();
		$(".croppedfile").slideUp(200);
		$('.imgcontainer').slideDown(200); //将隐藏的窗口div显示出来
		$('.info').slideUp(200); //将显示的窗口隐藏起来 
	});
	var img;
	var options = {
		thumbBox: '.thumbBox',
		spinner: '.spinner',
		imgSrc: '../images/avatar.png'
	}
	var cropper = $('.imageBox').cropbox(options);
	$('#upload-file').on('change', function() {
		var reader = new FileReader();
		reader.onload = function(e) {
			options.imgSrc = e.target.result;
			cropper = $('.imageBox').cropbox(options);
		}
		reader.readAsDataURL(this.files[0]);
		this.files = [];
	})
	$('#btnCrop').on('click', function() {
		img = cropper.getDataURL();
		$('.cropped').html('');
		$('.cropped').append('<img src="' + img + '" align="absmiddle" style="width:64px;margin-top:4px;border-radius:64px;box-shadow:0px 0px 12px #7E7E7E;" ><p>64px*64px</p>');
		$('.cropped').append('<img src="' + img + '" align="absmiddle" style="width:128px;margin-top:4px;border-radius:128px;box-shadow:0px 0px 12px #7E7E7E;"><p>128px*128px</p>');
		$('.cropped').append('<img src="' + img + '" align="absmiddle" style="width:180px;margin-top:4px;border-radius:180px;box-shadow:0px 0px 12px #7E7E7E;"><p>180px*180px</p>');
	})
	$('#btnZoomIn').on('click', function() {
		cropper.zoomIn();
	})
	$('#btnZoomOut').on('click', function() {
		cropper.zoomOut();
	})
	$('.closeimgcontainer').click(function() {
		$('.imgcontainer').slideUp(200); //将显示的窗口隐藏起来 
		$('.info').slideDown(200); //将隐藏的窗口显示
		$('.croppedfile').append('<img src="' + img + '" align="absmiddle" style="width:128px;margin-top:4px;border-radius:128px;box-shadow:0px 0px 12px #7E7E7E;">');
	    $(".croppedfile").slideDown(200);
	});
})